package br.com.millenium.service.veiculo.processaction;

import br.com.millenium.domain.manager.MilleniumManagerFactory;
import lumis.doui.processaction.ProcessActionHandler;
import lumis.portal.PortalException;

@SuppressWarnings("rawtypes")
public class CheckDuplicateVeiculoProcessActionHandler extends ProcessActionHandler
{
	@Override
	public void processAction() throws PortalException 
	{
		String veiculoNumero  = (String)getParameter ( "numero"  );
		String veiculoPlaca   = (String)getParameter ( "placa"   );
		String veiculoRenavam = (String)getParameter ( "renavam" );
		String veiculoChassi  = (String)getParameter ( "chassi"  );
		String veiculoId      = (String)(getParameter( "id"      ) == null ? "" : getParameter( "id" ));
		
		if( MilleniumManagerFactory.getVeiculoManager().isDuplicateVeiculoNumero(veiculoNumero, veiculoId, transaction))
			throw new PortalException( "STR_VECIULONUMERO_EXISTS;", getResource() );
		else if( MilleniumManagerFactory.getVeiculoManager().isDuplicateVeiculoPlaca(veiculoPlaca, veiculoId, transaction))
			throw new PortalException( "STR_VECIULOPLACA_EXISTS;", getResource() );
		else if( MilleniumManagerFactory.getVeiculoManager().isDuplicateVeiculoRenavam(veiculoRenavam, veiculoId, transaction))
			throw new PortalException( "STR_VECIULORENAVAM_EXISTS;", getResource() );
		else if( MilleniumManagerFactory.getVeiculoManager().isDuplicateVeiculoChassi(veiculoChassi, veiculoId, transaction))
			throw new PortalException( "STR_VECIULOCHASSI_EXISTS;", getResource() );
	}

}
